import { Tail } from './../core/effect/Tail';
import type { Camera } from "../core/Camera";
import { GNode } from "../core/GNode";
import { Input, KeyCode } from "../core/input/Input";

export class Ball extends GNode {
    public radius: number = 10;
    public color: string = "rgba(0, 0, 0, 1)";
    constructor() {
        super();
        let tail = new Tail();
        tail.color = this.color
        tail.tailWidth = this.radius * 2;
        this.addChild(tail);
    }

    update(deltaTime: number): void {
        if (Input.isKeyDown(KeyCode.KeyA)) {
            this.position.x -= 10;  
        }
        if (Input.isKeyDown(KeyCode.KeyW)) {
            this.position.y += 10;
        }
        if (Input.isKeyDown(KeyCode.KeyD)) {
            this.position.x += 10;
        }
        if (Input.isKeyDown(KeyCode.KeyS)) {
            this.position.y -= 10;
        }
        super.update(deltaTime);
    }
    render(context: CanvasRenderingContext2D, camera: Camera): void {
        context.beginPath();
        context.arc(this.position.x, this.position.y, this.radius, 0, Math.PI * 2);
        context.fillStyle = this.color;
        context.fill();
        super.render(context, camera);
    }
}
